import gps.api.GPSRule;
import gps.api.GPSState;
import gps.exception.NotAppliableException;


public class Rule implements GPSRule {

  private int col, row;
  
  public Rule(int c, int r){
    this.col = c;
    this.row = r;
  }
  
  @Override
  public GPSState evalRule(GPSState arg0) throws NotAppliableException {
    State resp = new State(((State)arg0).tablero);

    ((State)resp).tablero.set(this.col, this.row);
    
    checkDontEat(resp);
    
    return resp;
  }

    private void checkDontEat(State state) throws NotAppliableException {
      /*TODO tirar la excepcion si alguna reina se come a otra*/
      for(int i=1; i<8; i++){
        if( Math.abs(i-(i+1))==Math.abs(state.tablero.get(i)-state.tablero.get(i+1))
   ||  (Math.abs(state.tablero.get(i))==Math.abs(state.tablero.get(i+1)))
   ){
          throw new NotAppliableException();
        }
      }
    }
  

  @Override
  public Integer getCost() {
    // TODO Auto-generated method stub
    return 1;
  }

  @Override
  public String getName() {
    // TODO Auto-generated method stub
    return "Agrega reina en (" + this.row + "," + this.col + ")";
  }


  public int getCol() {
    return col;
  }


  public void setCol(int col) {
    this.col = col;
  }


  public int getRow() {
    return row;
  }


  public void setRow(int row) {
    this.row = row;
  }

}
